<?php
$brand_slug = pods_url_variable('last');
$brand_pod_item = new Pod('brand', $brand_slug);
$brand_name = ucwords(strtolower($brand_pod_item->get_field('name')));
$image = $brand_pod_item->get_field('logo');
$small_image =  wp_get_attachment_image_src($image[0][ID], 'thumbnail', false);
$deal_small_image = $small_image[0];
$webpage = $brand_pod_item->get_field('webpage');
?>
<div class="brand_head">
<?php if(!empty($deal_small_image)){ ?>
 	<img src="<?php echo $deal_small_image; ?>" alt="<?php echo $brand_name; ?>" />
<?php } ?>

<br />
<h1 id="f_margin"><?php echo ucwords(strtolower($brand_name)); ?> Offers</h1>
<div class="fright">
<?php if(!empty($webpage)){ ?>
<span class="brandpage_visit">
<a href="<?php echo $webpage ?>" target="_blank"><b>Visit <?php echo ucwords(strtolower($brand_name));?></b></a></span>
<?php }
buzzr_fb_like();
?>
</div>

<div class="clear"></div>

  <div class="brands_tabbed tabbed">
	<ul class="tabs">
		<li class="t1"><a class="t1 tab" title="Offers">Offers</a></li>
		<li class="t2"><a class="t2 tab" title="Profile">Profile</a></li>
		<div class="clear"></div>
	</ul>
 	
  	<div class="t1" id="t1">
  	
  	<div class="views">
	  <a class="grid g-button">Grid View</a>
	  <a class="list g-button">List View</a>
	</div>
	<div class="clear"></div>
	<div id="list_wrap">
		<ul class="list">
		<?php
			$list_view_deal = new Pod('deal');
			if($brand_slug == 'deilivery-chef'){
				$list_view_deal->findRecords('id DESC', 15, "t.camp_end > ".fix_date()." AND deal_provider.brandurl = '$brand_slug'");
			}else{
				$list_view_deal->findRecords('id DESC', 15, "t.camp_end > ".fix_date()." AND brand.brandurl = '$brand_slug'");
			}
			
			echo $list_view_deal->showTemplate('list_grid');
	  	?>
		</ul>
	</div>
	<div class="clear"></div>
	<div>
		<?php echo $list_view_deal->getPagination(); ?>
	</div>
	
	</div>
	
	<div class="t2" id="t2">
	<?php 
	$brand_profile = strip_tags($brand_pod_item->get_field('body'));
	$locations = trim(strip_tags($brand_pod_item->get_field('location')));
	?>
	<div class="brand_profile">
		<div class="store_profile"><?php echo $brand_profile; ?></div>
		<div class="store_address"><?php echo $locations; ?></div>
		<div class="clear"></div>
	</div>
	<div class="image_list">
	<?php 
		/*
		$Campaigns = new Pod('deal');
		$Campaigns->findRecords("id DESC", -1, "brand.name LIKE '$brand_name' && daily='0'");
			
		if($Campaigns->getTotalRows() > 0)
		{
		  while($Campaigns->fetchRecord())
		  {
  			   $camp_link = $Campaigns->get_field('camp_link');
               $guid = $Campaigns->get_field('image.guid');		
  			   $image_file_name = explode('.',basename($guid));
  			   $deal_tags['name'] = $Campaigns->get_field('tag_pick.name');
          	   if(!empty($deal_tags['name']))
          	   {
            		$count = count($deal_tags['name']);
		            if($count == '1')
		            {
		                $tags = stripslashes($deal_tags['name']);
		            }
		            else
		            {
		              for($i=0;$i<$count;$i++)
		              {
		                  $tags .= stripslashes($deal_tags['name'][$i]);
		                  if($i != ($count - 1))
		                  {
		                      $tags .= ' ';
		                  }
		              }
		            }
		           
		        }
        
         if(empty($deal_tags['name']))
          {
            $tags = $camp_link;
          }
           
		 if(!empty($guid)){
		 
		?>
         	<span style="margin: 10px;">
         		<a href="<?php echo get_bloginfo('url').'/deals/'.$camp_link; ?>">
         			<img alt="<?php echo $tags; ?>" src="<?php echo $guid; ?>" id="<?php echo 'deal_'.$name.'_'.$image_file_name[0]; ?>" style="width:130px;" />
         		</a>
		   </span>  
  		<?php  }
  		  else
  			   {
  			    $guid = $Campaigns->get_field('ext_image_url');				
  				  $image_file_name = explode('.',basename($guid));
        ?>
            <span style="margin: 10px;">
            	<a href="<?php echo get_bloginfo('url').'/deals/'.$camp_link; ?>">
            		<img alt="<?php echo $tags; ?>" src="<?php echo $guid; ?>" id="<?php echo 'brand_'.$name.'_'.$image_file_name[0]; ?>" style="width:130px;" />
            	</a>
            </span>
          <?php }
        }
      }
	   $images = $Record->get_field('brand_pics');
			if(!empty($images))
			{
				foreach($images as $value)
				{
				  $guid = $value['guid'];				
				  $image_file_name = explode('.',basename($guid));
		  ?>
					
			<span style="margin: 10px;">
				<img alt="<?php echo $image_file_name[0]; ?>" src="<?php echo $value['guid']; ?>" id="<?php  echo 'brand_'.$name.'_'.$image_file_name[0]; ?>" style="width:130px" />
			</span>
       <?php  }
			}
	 */  ?>
		
	</div>
		
	</div>

	
  </div>
  </div>